<?php
class Usuarios_Form_Registrar extends Form_Cna {
	
		
	public function __construct($options = null) {
		parent::__construct($options);
	}
	
	public function init() {
		$domConfig = Zend_Registry::get('domConfig'); //esto se crea en el bootstrap
		
		//Crea el formulario para el registro de usuarios del sistema
		$this->setName ( 'info_usuario' );
		$this->setMethod("POST");
		$this->setAttrib("autocomplete","on");
		
		$codusuario = new Zend_Form_Element_Hidden("codusuario");
		$array_elements[]=$codusuario;
		
		$cedula = new Zend_Form_Element_Text ( 'cedula' );
		$cedula->setLabel( 'Identificación : ' );
		$cedula->setRequired ( true );
		$cedula->addFilter ( 'StripTags' );
		$cedula->addFilter ( 'StringTrim' );
		$cedula->addValidator ( 'digits' );
		$array_elements[]=$cedula;
		
		$tipodocumento = new Zend_Form_Element_Select('tipodocumento');
		$tipodocumento->setRegisterInArrayValidator(false);
		$tipodocumento->setMultiOptions($domConfig->DOM_TIPODOCUMENTO->toArray());
        $tipodocumento->setRequired(true);
        $array_elements[]=$tipodocumento;
                      
		$nombres = new Zend_Form_Element_Text ( 'nombres' );
		$nombres->setLabel ( 'Nombres : ' );
		$nombres->setAttribs(array('size'=>30));
		$nombres->setRequired ( true );
		$nombres->addFilter ( 'StripTags' );
		$nombres->addFilter ( 'StringTrim' );
		$array_elements[]=$nombres;
				               
		$apellidos = new Zend_Form_Element_Text ( 'apellidos' );
		$apellidos->setLabel ( 'Apellidos : ' );
		$apellidos->setAttribs(array('size'=>30));
		$apellidos->setRequired ( true );
		$apellidos->addFilter ( 'StripTags' );
		$apellidos->addFilter ( 'StringTrim' );
		$array_elements[]=$apellidos;
				
		$estado   = new Zend_Form_Element_Hidden("estadocna");
		$estado->setValue(1);
		$array_elements[]=$estado;
		
		$sacescna = new Zend_Form_Element_Hidden("sacescna");
        $sacescna->setValue(3);
        $array_elements[]=$sacescna;
        
		$genero = new Zend_Form_Element_Select('genero');
		$genero->setRegisterInArrayValidator(false);
		$genero->setLabel ( 'Genero : ' );
		$genero->setMultiOptions($domConfig->DOM_GENERO->toArray());
        $genero->setRequired(true);
        $array_elements[]=$genero;

		$direccionresidencia = new Zend_Form_Element_Text ( 'direccionresidencia' );
		$direccionresidencia->setLabel ( 'Dirección : ' );
		$direccionresidencia->setAttribs(array('size'=>30));
		$direccionresidencia->setRequired ( true );
		$direccionresidencia->addFilter ( 'StripTags' );
		$direccionresidencia->addFilter ( 'StringTrim' );
		$array_elements[]=$direccionresidencia;

		$ubicacion = new Zend_Form_Element_Text ( 'ubicacion' );
		$ubicacion->setLabel ( 'Ubicación : ' );
		$ubicacion->setAttribs(array('size'=>30));
		//$ubicacion->setRequired ( true );
		$ubicacion->addFilter ( 'StripTags' );
		$ubicacion->addFilter ( 'StringTrim' );
		$array_elements[]=$ubicacion;
		
		$codubicacion = new Zend_Form_Element_Hidden("codubicacion");
		$codubicacion->setRequired(true);
		$array_elements[]=$codubicacion;

		$emailexterno = new Zend_Form_Element_Text ( 'emailexterno' );
		$emailexterno->setLabel ( 'Personal : ' );
		$emailexterno->setAttribs(array('size'=>30));
		$emailexterno->setRequired ( true );
		$emailexterno->addFilter ( 'StripTags' );
		$emailexterno->addFilter ( 'StringTrim' );
		$emailexterno->addValidator ( 'EmailAddress');
		$array_elements[]=$emailexterno;

		$emailalterno = new Zend_Form_Element_Text ( 'emailalterno' );
		$emailalterno->setLabel ( 'Alternativo : ' );
		$emailalterno->setAttribs(array('size'=>30));
		$emailalterno->setRequired ( true );
		$emailalterno->addFilter ( 'StripTags' );
		$emailalterno->addFilter ( 'StringTrim' );
		$emailalterno->addValidator ( 'EmailAddress' );
		$array_elements[]=$emailalterno;

		$telefonocelular = new Zend_Form_Element_Text ( 'telefonocelular' );
		$telefonocelular->setLabel ( 'Celular : ' );
		$telefonocelular->setAttribs(array('size'=>30));
		$telefonocelular->setRequired ( true );
		$telefonocelular->addFilter ( 'StripTags' );
		$telefonocelular->addFilter ( 'StringTrim' );
		$array_elements[]=$telefonocelular;

		$telefonoresidencia = new Zend_Form_Element_Text ( 'telefonoresidencia' );
		$telefonoresidencia->setLabel ( 'Teléfono casa : ' );
		$telefonoresidencia->setAttribs(array('size'=>30));
		//$telefonoresidencia->setRequired ( true );
		$telefonoresidencia->addFilter ( 'StripTags' );
		$telefonoresidencia->addFilter ( 'StringTrim' );
		$array_elements[]=$telefonoresidencia;

		$telefonotrabajo = new Zend_Form_Element_Text ( 'telefonotrabajo' );
		$telefonotrabajo->setLabel ( 'Teléfono oficina : ' );
		$telefonotrabajo->setAttribs(array('size'=>30));
		$telefonotrabajo->setRequired ( true );
		$telefonotrabajo->addFilter ( 'StripTags' );
		$telefonotrabajo->addFilter ( 'StringTrim' );
		$array_elements[]=$telefonotrabajo;

		$fax = new Zend_Form_Element_Text ( 'fax' );
		$fax->setLabel ( 'Fax : ' );
		$fax->setAttribs(array('size'=>30));
		//$fax->setRequired ( true );
		$fax->addFilter ( 'StripTags' );
		$fax->addFilter ( 'StringTrim' );
		$array_elements[]=$fax;
		
//        $captcha = new Zend_Form_Element_Captcha('imgvalidation', array('label' => "Please verify you're a human",
//        																'captcha' => array('captcha' => 'Figlet',
//        																					'wordLen' => 5,
//        																					'timeout' => 100 ) ));
        
        

		$baseUrl = Zend_Controller_Front::getInstance ()->getBaseUrl()."/captcha";
		$ruta_archivos = APPLICATION_PATH."/../cna/captcha";
		$ruta_fonts = APPLICATION_PATH."/../cna/fonts/Arial.ttf";

        $captcha = new Zend_Form_Element_Captcha('imgvalidation', array(
            'label' => "Digite los caracteres que se visualizan en la imagen",
            'captcha' => 'Image',
            'captchaOptions' => array(
            'captcha' => 'Image',
            'wordLen' => 6,
            'timeout' => 300,
            'imgDir' => $ruta_archivos, // This folder has to have 777 permissions.
            'imgUrl' => $baseUrl,
            'width' => 200,
            'height' => 60,
            'font' => $ruta_fonts
            ),
        ));
        $captcha->setRequired ( true );
        $array_elements[]= $captcha;

		$submit = new Zend_Form_Element_Submit ( 'btnSubmit' );
		$submit->setValue('Guardar');
		$submit->setLabel("Guardar");
		$submit->setAttrib("class", "iceCmdBtn");
		$array_elements[]=$submit;
		
		$this->addElements ($array_elements);
		
		$this->loadViewScriptDecorators();
//        $this->loadTableDecorato$ruta_archivos$ruta_archivosrs();
	}
	
	public function loadViewScriptDecorators() {
		$this->setDecorators ( array (array ('viewScript', array ('viewScript' => 'viewscripts/registro_form.phtml' ) ) ) );
	}

}